﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class feedback : System.Web.UI.Page
{
    protected MODEL.Users currentuser = new MODEL.Users();
    BLL.FeedBack bllfb = new BLL.FeedBack();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (common.isLoginOrNot())
        {
            currentuser = ((MODEL.Users)Session["currentUser"]);
            Bind(1);
        }
        else
        {
            MessageBox.Show(this, "请先登录");
            MessageBox.script(Page, "window.location='index.aspx';");
        }
    }

    public void Bind(int pagenum)
    {
        int count = bllfb.getPage();
        if (pagenum < 1)
        {
            pagenum = 1;
        }
        if (pagenum > count)
        {
            pagenum = count;
        }
        //别要忘了这个
        btnpre.Enabled = true;
        btnnext.Enabled = true;
        if (pagenum == 1)
        {
            btnpre.Enabled = false;
        }
        if (pagenum == count)
        {
            btnnext.Enabled = false;
        }
        List<MODEL.FeedBack> models = bllfb.getAllFB(pagenum);
        if (models != null)
        {
            foreach (MODEL.FeedBack fb in models)
            {
                if (fb.Message.Length > 15)
                {
                    fb.Message = fb.Message.Substring(0, 15);
                }
            }
        }
        rpFeedBack.DataSource = models;
        rpFeedBack.DataBind();
        pageNum.Text = pagenum.ToString();
        pageCount.Text = count.ToString();
    }

    //上一页
    protected void btnpre_Click(object sender, EventArgs e)
    {
        int currentpage = Convert.ToInt32(pageNum.Text);
        currentpage--;
        Bind(currentpage);
    }
    //下一页
    protected void btnnext_Click(object sender, EventArgs e)
    {
        int currentpage = Convert.ToInt32(pageNum.Text);
        currentpage++;
        Bind(currentpage);
    }
    //跳转
    protected void btnjump_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            int pagenum = Convert.ToInt32(txtjump.Text);
            Bind(pagenum);
        }
    }
}